package com.pt5.pthouduan.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author ljx
 * @since 2025-04-14
 */
@TableName("torrent")
public class Torrent implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId("torrentid")
    private Long torrentid;

    private Long uploaderid;

    private Long promotionid;

    private Integer categoryid;

    private String infohash;

    private String torrenttitle;

    private String dpi;

    private String caption;

    private Long torrentsize;

    //private String announce;

    private String description;

    private LocalDateTime uploadtime;

    private LocalDateTime lastseed;

    private Long downloadCount = 0L;

    private String filename;

    private String path;




    public void setFilename(String filename) {
        this.filename = filename;
    }
    public String getFilepath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;
    }

    public LocalDateTime getLastseed(){
        return lastseed;
    }
    public void setLastseed(LocalDateTime lastseed){
        this.lastseed = lastseed;
    }



    //private String createdBy;

    public LocalDateTime getUploadTime() {
        return uploadtime;
    }
    public void setUploadTime(LocalDateTime uploadTime) {
        this.uploadtime = uploadTime;
    }
    public Long getDownloadCount() {
        return downloadCount;
    }
    public void setDownloadCount(Long downloadCount) {
        this.downloadCount = downloadCount;
    }

    public String getDescription(){
        return description;
    }
    public void setDescription(String description){
        this.description = description;
    }


    public Long getUploader_id(){
        return uploaderid;
    }

    public void setUploader_id(Long uploader_id){
        this.uploaderid = uploader_id;
    }


//    public String getAnnounce() {
//        return announce;
//    }
//
//    public void setAnnounce(String announce) {
//        this.announce = announce;
//    }

//    public static Torrent create(File source, URI announce, String createdBy)throws NoSuchAlgorithmException, IOException {
//        if (source == null || !source.exists()) {
//            throw new IllegalArgumentException("源文件不存在");
//        }
//        if (announce == null) {
//            throw new IllegalArgumentException("Announce URL不能为空");
//        }
//
//        Torrent torrent = Torrent.create(source, announce, createdBy != null ? createdBy : "PT站点");
//
//        //torrent.save(outputFile);
//        return torrent;
//    }
//    public void save(File outputFile) throws IOException{
//        if (outputFile == null ) {
//            throw new IllegalArgumentException("输出文件不能为空");
//        }
//        //确保目录存在
//        File parent = outputFile.getParentFile();
//        if (!parent.exists() || parent != null) {
//            parent.mkdirs();
//        }
//        //序列化并写入文件
//        try(FileOutputStream fos = new FileOutputStream(outputFile);){
//            byte[] data = torrent.encode();
//            fos.write(buffer.array(),buffer.arrayOffset(),buffer.remaining());
//        }
//        if(!outputFile.setReadable(true, false)){
//            System.err.println("警告：无法设置文件可读权限");
//        }
//    }

    public Long getTorrentid() {
        return torrentid;
    }

    public void setTorrentid(Long torrentid) {
        this.torrentid = torrentid;
    }

    public Long getPromotionid() {
        return promotionid;
    }

    public void setPromotionid(Long promotionid) {
        this.promotionid = promotionid;
    }

    public Integer getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(Integer categoryid) {
        this.categoryid = categoryid;
    }

    public String getInfoHash() {
        return infohash;
    }

    public void setInfoHash(String infoHash) {
        this.infohash = infoHash;
    }

    public String getTorrentTitle() {
        return torrenttitle;
    }

    public void setTorrentTitle(String torrentTitle) {
        this.torrenttitle = torrentTitle;
    }

    public String getDpi() {
        return dpi;
    }

    public void setDpi(String dpi) {
        this.dpi = dpi;
    }

    public String getCaption() {
        return caption;
    }

    public void setCaption(String caption) {
        this.caption = caption;
    }

    public Long getTorrentSize() {
        return torrentsize;
    }

    public void setTorrentSize(Long torrentSize) {
        this.torrentsize = torrentSize;
    }

    @Override
    public String toString() {
        return "Torrent{" +
        "torrentid = " + torrentid +
        ", promotionid = " + promotionid +
        ", categoryid = " + categoryid +
        ", infoHash = " + infohash +
        ", torrentTitle = " + torrenttitle +
        ", dpi = " + dpi +
        ", caption = " + caption +
        ", torrentSize = " + torrentsize +
        "}";
    }


    public String getFilePath() {
        return path;
    }


    public String getFilename() {
        return filename;
    }
    public void setfilename(String filename) {
        this.filename = filename;
    }
}
